package com.zqcy.workbench.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.onemdos.base.message.protocal.msgstruct.MsgConf;
import com.onemdos.push.OneMDOSPush;
import com.onemdos.push.callback.OneMDOPushListCallback;
import com.shinemo.base.core.utils.ToastUtil;
import com.zqcy.workbench.R;
import com.zqcy.workbench.adapter.InformationAdapter;
import com.zqcy.workbench.utils.Utils;

import java.util.ArrayList;
import java.util.List;

/**
 * 消息中心页面
 */
public class InformationActivity extends AppCompatActivity {

    private RecyclerView informationRecyclerView;
    private ImageView informationBack;
    private InformationAdapter informationAdapter;
    private List<MsgConf> msgConfList = new ArrayList<>();

    public static void startActivity(Context context) {
        Intent intent = new Intent(context, InformationActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_information);
        Utils.setColor(this, getResources().getColor(R.color.white));
        initView();
        initListener();
        getInformationList();
    }

    /**
     * 请求推送消息list
     * pageNum 第几页(默认传1) pageAmount 每页item数 beginDay 开始时间(long) endDay 截止时间(long)
     * 由开发者自行实现分页等逻辑
     */
    private void getInformationList() {
        OneMDOSPush.getPushMsgList(1, 1000, 0, 0, new OneMDOPushListCallback() {
            @Override
            public void onFailed(int errorCode) {
                ToastUtil.show(InformationActivity.this, getResources().getString(R.string.fail_get_push));

            }

            @Override
            public void onGetMessage(List<MsgConf> list) {
//                ToastUtil.show(InformationActivity.this, getResources().getString(R.string.success_get_push));
                msgConfList.clear();
                msgConfList.addAll(list);
                informationAdapter.notifyDataSetChanged();
            }
        });
    }

    private void initListener() {
        informationBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initView() {
        informationBack = findViewById(R.id.information_back);
        informationRecyclerView = findViewById(R.id.information_recylcerview);
        informationAdapter = new InformationAdapter(this, msgConfList);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        informationRecyclerView.setLayoutManager(layoutManager);
        informationRecyclerView.setAdapter(informationAdapter);

    }
}